<template>
    <div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>ID</td>
                    <td>房型名称</td>
                    <td>房型图片</td>
                    <td>房型大小</td>
                    <td>操作</td>
                </tr>
                <tr v-for="item in data.list" :key="item.Id">
                    <td>{{ item.Id }}</td>
                    <td><img :src="item.Photo" width="60" height="60" alt=""/></td>
                    <td>{{ item.Nametype }}</td>
                    <td>{{ item.Size }}</td>
                    <td><input type="button" value="删除" class="btn btn-danger" @click="del(item.Id)"/></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive, onMounted}from 'vue'
import axios from 'axios';
import {useRouter,useRoute} from 'vue-router'
const router=useRouter();
const route=useRoute();

let data:any=reactive({
    list:[],
})

let queryinfo:any=reactive({
    name:'',
})

onMounted(()=>{
    getlist();
})

const getlist=()=>{
    axios({
        url:'/api/Hotel/Gethotel',
        method:'get',
        params:queryinfo
    })
    .then(res=>{
        console.log(res);
        data.list=res.data;
    })
    .catch(err=>{
        console.log(err);
    })
}

const del=(id:any)=>{
    if(!confirm("确认删除吗")){
        return;
    }
    axios({
        url:'/api/Hotel/Dele',
        method:'delete',
        params:{id:id},
    })
    .then(res=>{
        console.log(res);
        if(res.data>0){
            alert('删除成功');
            getlist();
        }
        else{
            alert('删除失败');
        }
    })
    .catch(err=>{
        console.log(err);
    })
}
</script>

<style scoped>

</style>